//
//  EmitterPage.swift
//  RKTemplate
//
//  Created by zhaoke on 2023/9/25.
//

import UIKit

class EmitterPage: RKBaseCtrl, Emitterable {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        self.title = "粒子动画"
        let btn = UIButton(type: .custom)
        let height = UIScreen.main.bounds.size.height
        let width = UIScreen.main.bounds.size.width
        btn.frame = CGRect(x: (width-220)/2, y: height-80, width: 220, height: 40)
        btn.setTitleColor(.white, for: .normal)
        btn.backgroundColor = .orange
        btn.setTitle("Start", for: .normal)
        btn.addTarget(self, action: #selector(startOrStopEmitteringAction(_:)), for: .touchUpInside)
        btn.layer.cornerRadius = 5
        view.addSubview(btn)
       
    }
    
    @objc func startOrStopEmitteringAction(_ sender: UIButton) {
        sender.isSelected = !sender.isSelected;
        if sender.currentTitle == "Start" {
            sender.setTitle("Stop", for: .selected)
        } else {
            sender.setTitle("Start", for: .normal)
        }
        let point = CGPoint(x: sender.center.x, y: sender.center.y)
        sender.isSelected ? startEmittering(point) : stopEmittering()
    }
}
